<#import "../tpl/pageTep.ftl" as page>
<@page.pageBase currentMenu="活动管理">
<style>
    .button-large {
        font-size: 16px;
    }

    hr {
        border-color: #009688;
    }

    .control-group {
        width: 1000px;
    }

    .webuploader-pick {
        background: none;
        padding: 0;
    }
</style>
<div class="xm-offline">
    <div class="row">
        <div class="panel">
            <div class="panel-header">
                <a href="${basepath}/rest/manage/activity/toActivityPicture">返回上一级</a>
            </div>
            <div class="panel-body">
            <#--form表单提交，相当于data-->
                <form id="checkForm" class="form-horizontal" action="${basepath}/rest/manage/activitypicture/updateJson"
                      method="post">
                    <input type="hidden" name="id" value="${e.id!}">
                    <div class="control-group">
                        <label class="control-label">
                            <s>*</s>
                            上传者：
                        </label>

                        <div class="controls">
                            <input type="text" class="control-text span-width span5 name"
                                   name="userName" readonly  value="${e.nickname!}" >
                        </div>
                    </div>
                    <div class=" control-group">
                        <label class="control-label"> <s>*</s>活动感想：</label>
                        <div class="controls  control-row4 mar0">
                                <textarea readonly class="span5"  name="comment" value="${e.comment!}">
                                </textarea>
                        </div>
                    </div>

                    <h3 class="offset2">宣传图片

                    </h3>
                    <hr>
                    <input type="hidden" class="control-text span-width " name="picture" id="picture"
                           data-rules="{required:true}" data-messages="{required:'图片不能为空'}" value="${e.picture!}">

                    <div id="imagesGrid" class="xm-grid">

                    </div>
                    <div class="control-group">
                        <label class="control-label"><s>*</s>审核结果：</label>
                        <div class="controls"><select name="status" class="span5"><option>请选择</option><option value="unPass">未通过</option><option value="pass">已通过</option></select></div>
                    </div>
                    <div class="centered">
                        <button type="submit" class="button  button-large  button-success">确定</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
    var Grid = BUI.Grid;
    var Select = BUI.Select;
    var Store = BUI.Data.Store;
    var Data = BUI.Data;
    var check = new BUI.Form.Form({
        srcNode: '#checkForm',
        submitType: 'ajax',
        callback: function (data) {
            if (data.success == true) {
                window.location.href = "${basepath}/rest/manage/activity/toActivityPicture"
            } else {

            }
        }
    }).render();
    /*--------------------------活动图片列表  begin--------------------*/
    /**
     * 图片信息
     * @type {*[]}
     */
    var imagesColumns = [
        {title: '序号',  elCls: 'center', width: '30%',renderer:function (value,data,index) {
                return (index+1);
            }},
        {
            title: '图片', dataIndex: 'url',elCls: 'center', width: '30%', renderer: function (data) {
                return '<img src="${basepath}/' + data + '" width="100px" height="100px"/>'
            }
        },
        {
            title: '编辑', dataIndex: 'title', elCls: 'center', width: '40%', renderer: function (data, obj, index) {
                return '<a href="javascript:delImages(' + index + ')">删除</a>';
            }
        }
    ];
    /**
     * 删除缓存图片信息
     * @param index
     */
    function delImages(index) {
        BUI.Message.Confirm('确认要删除吗？', function () {
            var record = imagesStore.findByIndex(index);
            imagesStore.remove(record);
            var imgStr = imagesStore.getResult();
            var imgArr = new Array();
            for (var i = 0; i < imgStr.length; i++) {
                imgArr[i] = imgStr[i].url
            }
            $("#picture").val(imgArr.join(","));
        }, 'question');
    }

    var imagesStore = new Store({});
    var imagesGrid = new Grid.Grid({
        render: '#imagesGrid',
        width: '100%',//如果表格使用百分比，这个属性一定要设置
        columns: imagesColumns,
        idField: 'title',
        store: imagesStore
    }).render();

    /*--------------------------活动图片列表  end--------------------*/
    /**
     * 初始化图片列表数据源
     * */
    function initImagesStore() {
        var imgArr = $("#picture").val().split(',');
        for (var i = 0; i < imgArr.length; i++) {
            var obj = new Object();
            obj.url = imgArr[i];
            obj.state = "SUCCESS";
            imagesStore.add(obj);
        }
    }
    initImagesStore();
    function GetRequest() {
        var url = decodeURI(decodeURI(location.search));
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
            }
            return theRequest;
        }
    }
    var postData = GetRequest();
    var name = postData.name;
    $('.name').val(name);

</script>

</@page.pageBase>